<?php

namespace app\controller;

use app\BaseController;
use think\App;
use think\facade\Cache;

class BlackConfigurationWarehouseController extends BaseController
{


    /**
     * @var \think\cache\Driver
     */
    private $redis;
    private $leisureKey = 'cod_black_leisure_configuration_warehouse';
    private $busyKey = 'cod_black_busy_configuration_warehouse';
    private $bcwArr = [
        'cod1' => [
            "ZUH140" => ['user' => '140api15', 'pwd' => '83kdksls902'],
            "ZUH118" => ['user' => '118api7', 'pwd' => 'epe3pjl38x8s'],
            "MFM327" => ['user' => 'GUIHONG327', 'pwd' => 'p5es4d85'],
        ],
        'cod2' => [
            "ZUH140" => ['user' => 'CODAPI140', 'pwd' => 'epe3pjl38x8s'],
            "ZUH118" => ['user' => 'CODAPI118', 'pwd' => 'epe3pjl38x8s'],
            "MFM327" => ['user' => 'CODAPI327', 'pwd' => 'epe3pjl38x8s'],
        ]
    ];
    private $_bcwArr = [
        'cod1' => '140api15|118api7|GUIHONG327',
        'cod2' => 'CODAPI140|CODAPI118|CODAPI327'
    ];


    public function __construct(App $app)
    {
        $this->redis = Cache::store('redis');
        parent::__construct($app);
    }


    public function getList()
    {
        $result['leisure'] = array_map(function ($id) {
            return $this->_bcwArr[$id];
        }, $this->redis->lRange($this->leisureKey, 0, -1));

        $result['busy'] = array_map(function ($id) {
            return $this->_bcwArr[$id];
        }, $this->redis->lRange($this->busyKey, 0, -1));

        return $this->returnJson($result);
//        $arr=[
//            "140"=>['user'=>'140api15', 'pwd'=> '83kdksls902'],
//            "118"=>['user'=>'118api7', 'pwd'=> 'epe3pjl38x8s'],
//            "327"=>['user'=>'GUIHONG327', 'pwd'=> 'p5es4d85'],
//        ];
//        $this->redis->lPush($this->leisureKey, json_encode($arr));

    }


}